package com.meizhuo.listview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;

import com.bumptech.glide.Glide;
import com.meizhuo.listview.DataSaveUtil.ListDataSave;
import com.meizhuo.listview.network_data.send_data.Register;

import java.util.ArrayList;

public class DetailActivity extends Activity {

    private AppCompatImageView user_pic;
    private TextView user_nickname;
    private TextView user_username;
    private TextView user_area;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail_activity);
        initView();

        Intent intent = getIntent();
        //获取bundle
        Bundle bundle = intent.getExtras();
        //获取绑定数据
        Integer Index = bundle.getInt("Index");

        // 从数据存储中获得用户的信息
        ArrayList<Register> list = (ArrayList<Register>) ListDataSave.getInstance(getApplication(), "data").getDataList("List");
        Register data = list.get(Index);
        System.out.println(data);
        user_nickname.setText(data.getNickname());
        user_username.setText("账号  "+data.getUsername());
        if(data.getArea()!= null){
            user_area.setText("地区  "+data.getArea());
        }
        Glide.with(user_pic.getContext()).load(data.getAvatar()).into(user_pic);

    }

    private void initView() {
        user_pic = (AppCompatImageView) findViewById(R.id.user_pic);
        user_nickname = (TextView) findViewById(R.id.user_nickname);
        user_username = (TextView) findViewById(R.id.user_username);
        user_area = (TextView) findViewById(R.id.user_area);
    }
}
